const app = require('fastify')({
    logger: true,
    ignoreTrailingSlash: true
})
var nodejieba = require("nodejieba");


app.get('/', async (req, res) => {
    return res.send({ hello: 'world' })
})

app.post('/', async (req, res) => {
    if (req.body.text) {
        return res.send(nodejieba.tag(req.body.text))
    } else {
        return res.send({})
    }
})

const start = async () => {
    try {
        await app.listen(6000, '0.0.0.0')
        await nodejieba.load()
    } catch (err) {
        app.log.error(err)
        process.exit(1)
    }
}
start()